package org.oos.dao.lists.impl;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;

import org.oos.atom.AtomEntity;
import org.oos.atom.impl.AtomFeed;
import org.oos.dao.Dao;
import org.oos.lists.DynamicList;

public class ReadAllList<Entity extends AtomEntity, Feed extends AtomFeed<Entity>>
		extends AbstractList<Entity> implements DynamicList<Entity> {
	private static final long serialVersionUID = 8262342315763064111L;
	
	private List<Entity> all = new ArrayList<Entity>();

	/**
	 * 
	 * Create a new ReadOnly List from the provided feed (first page) as well a
	 * {@link Dao} to provide the following pages.
	 * 
	 * @param dao
	 * @param feed
	 */
	public ReadAllList(Dao<Entity, Feed> dao, Feed feed) {
		super();
		this.all = feed.getEntries();
	}

	@Override
	public List<Entity> getAll() {
		return all;
	}

	@Override
	public Entity get(int index) {
		return all.get(index);
	}

	@Override
	public int size() {
		return all.size();
	}

	@SuppressWarnings("unchecked")
	@Override
	public ReadAllList<Entity, Feed> clone()
			throws CloneNotSupportedException {
		return (ReadAllList<Entity, Feed>) super.clone();
	}

	@Override
	public void loadAll() {
		getAll();
	}

}
